package 函数式接口.Stream流的常用方法;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 常用方法
 */
public class Test03 {

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("张三");
        list.add("李四");
        list.add("王五");

        Stream<String> stream01 = list.stream();
        Stream<String> stream02 = Stream.of("赵六", "钱七", "孙八");

//        method4Limit(stream01);
//
//        method4Concat(stream01, stream02);

//        method4Collect(stream01, stream02);
//
        method4Distinct(stream01);

        method4skip(stream01);
    }

    private static void method4skip(Stream<String> stream01) {
        stream01.skip(1).forEach(string -> System.out.println(string));
    }

    private static void method4Distinct(Stream<String> stream01) {
        List<String> collect = stream01.distinct().collect(Collectors.toList());
        System.out.println(collect);
    }

    private static void method4Collect(Stream<String> stream01, Stream<String> stream02) {
        List<String> collect = Stream.concat(stream01, stream02).collect(Collectors.toList());
        System.out.println(collect.toString());
    }

    private static void method4Concat(Stream<String> stream01, Stream<String> stream02) {
        Stream.concat(stream01, stream02).forEach(s -> System.out.println(s));
    }

    private static void method4Limit(Stream<String> stream) {
        stream.limit(2).forEach(s -> System.out.println(s));
    }
}
